package org.jasig.cas.ticket.registry;

import java.util.HashMap;

import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;

public class MySessionContext {

	private static MySessionContext instance;
	
	private HashMap<String ,HttpSession> myMap;
	
	private MySessionContext(){
		myMap = new HashMap<String ,HttpSession>();
	}
	
	public static MySessionContext getInstance(){
		if(instance == null ){
			instance = new MySessionContext();
		}
		return instance;
	}
	
	public synchronized void addSession(HttpSession session){
		if(session != null){
			myMap.put(session.getId(), session);
		}
	}
	
	public synchronized void delSession(HttpSession session){
		if(session != null){
			myMap.remove(session.getId());
		}
	}
	public synchronized void delSessionById(String sessionId){
		if(!StringUtils.isEmpty(sessionId)){
			myMap.remove(sessionId);
		}
	}
	
	public synchronized HttpSession getSession(String sessionId){
		if(StringUtils.isEmpty(sessionId))
			return null;
		return myMap.get(sessionId);
	}
}
